Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Livecheck#url: Don't convert URL symbol to string #10309

Merged
merged 2 commits into from Jan 15, 2021
Merged

Livecheck#url: Don't convert URL symbol to string #10309

merged 2 commits into from Jan 15, 2021

Conversation

samford
Copy link
Member

@samford samford commented Jan 13, 2021

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew style with your changes locally?
  • Have you successfully run brew typecheck with your changes locally?
  • Have you successfully run brew tests with your changes locally?
  • Have you successfully run brew man locally and committed any changes?

An issue that we've encountered in at least one homebrew/core formula is that url :head won't work in a livecheck block if the formula uses a head block. The livecheck block comes before the head block, so the head URL isn't defined when the livecheck block #url method is called.

In #10157, I proposed that we could resolve this issue by moving head blocks after stable blocks in formulae, so they both come before the livecheck block. Some Homebrew members supported this while others preferred to simply move the livecheck block after the head block. Both of these options would lead to some level of unhappiness in the end.

While discussing these options, @SeekingMeaning asked if we could modify Livecheck#url to simply store the symbol from the livecheck block and convert it to the formula URL string sometime after the formula is parsed. I had already considered doing this for other reasons (see #10157 (comment) for details), so I agreed that this was the most amenable solution to this particular issue.


With that in mind, this PR modifies Livecheck#url to simply store the value it's passed (a string or symbol). We do the conversion from a URL symbol to the formula/cask URL string in #latest_version, using a new #livecheck_url_to_string method.

This solution resolves the issue described above but it also allows us to surface information in the debug and JSON output about whether a URL symbol was used in the livecheck block. The existing Livecheck#url setup prevented us from being able to do this before and that was initially why I thought about pursuing this change.

Along the way, I did some minor refactoring in livecheck's tests. There's still a lot of room for improvement when it comes to tidying up these tests but that's something for a later PR.

If/when this is merged, I'll close #10157 and Homebrew/homebrew-core#67824, as they won't be necessary.

@BrewTestBot
Copy link
Member

Review period will end on 2021-01-14 at 03:14:54 UTC.

@BrewTestBot BrewTestBot added the waiting for feedback Merging is blocked until sufficient time has passed for review label Jan 13, 2021
HEAD_URL = "https://github.com/Homebrew/brew.git"
HOMEPAGE_URL = "https://brew.sh"
LIVECHECK_URL = "https://formulae.brew.sh/api/formula/ruby.json"
STABLE_URL = "https://brew.sh/test-0.0.1.tgz"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use let instead of constants.

Copy link
Member Author

@samford samford Jan 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that let is more appropriate. I was using constants because a string that's defined using let isn't available in the formula and cask blocks. When using a constant, url STABLE_URL works in the f formula. When using let(:stable_url) { ... }, url stable_url gives an undefined local variable or method `stable_url' error.

My goals were to reduce repetition of string literals in multiple places and to make the tests easier to read (i.e., it's somewhat ambiguous as to what "https://brew.sh/test-0.0.1.tgz" references but STABLE_URL is clear).


I've updated this to use string literals in the formula/cask definitions and let to define strings that can be referenced in tests (so we can use something that's readily understandable like stable_url instead of an ambiguous string literal).

I'm considering trying to extract the various formulae/casks that we define in livecheck's tests into separate files (like test/support/fixtures/cask/Casks) sometime in the future. If we go down that path, we would have to lose the constants anyway, so I'm good with the let approach here.

@samford samford marked this pull request as ready for review January 13, 2021 14:45
@BrewTestBot BrewTestBot removed the waiting for feedback Merging is blocked until sufficient time has passed for review label Jan 14, 2021
@BrewTestBot
Copy link
Member

Review period ended.

@samford samford merged commit 8869208 into Homebrew:master Jan 15, 2021
@samford samford deleted the livecheck-dsl-avoid-url-symbol-conversion branch January 15, 2021 21:08
@BrewTestBot BrewTestBot added the outdated PR was locked due to age label Feb 16, 2021
@Homebrew Homebrew locked as resolved and limited conversation to collaborators Feb 16, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated PR was locked due to age
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants